:- module(startdbserver, [main/0], []).

%%%%%%%%%%%%%%%%%%%%%%%%%%%% Needed modules %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- use_module(library(read)).
:- use_module(library(streams)).
:- use_module(library('make/system_extra')).
%%%%%%%%%%%%%%%%%%%%%%%%%%%% Defined predicates  %%%%%%%%%%%%%%%%%%%%%%%%
:- include(password).

:- use_module(amos(configuration)).

main:- 
	current_executable(E),
	absolute_file_name(E,'','','.',_,_,Dir),
	atom_concat(Dir, '/.addr', Addr),
	open_input(Addr, Stream),
	read(DirAddr),
	close_input(Stream),
	ls(DirAddr, '.lock', Lock),
	(Lock = [] ->
	 atom_concat(Dir, '/dbserver', Dbserver),
         log_dir(DirLog),
	 atom_concat(DirLog, '/dbserver.log', Log),
	 do([Dbserver, ' >> ', Log, ' 2>&1 &'], fail), 
	 Output = 'AMOS started!'
	;
	 Output = 'An error ocurred. Probably AMOS is already running'
	),
	display(Output), nl.

%% Version comment prompting control for this file.
%% Local Variables: 
%% mode: CIAO
%% update-version-comments: "off"
%% End:

